/**
 * Created by home on 2018/1/12.
 */
/**
 * Created by home on 2018/1/12.
 */
//    var a = 'hello';
//   退出登录
$("#out").on('click',function () {
    alert('退出')
})
//   点击菜单 菜单消失
$(".submenu ").on('click',function () {
    submenuHover()
})

$(".avatarView").mouseenter(function () {
    submenu()

})
$(".avatarView").mouseleave(function (e) {
    var direction = moveDirection(this,e);
    if(direction != 2 )
    {
        submenuHover()
    }
})
$(".submenu").mouseleave(function (e) {
    submenuHover()
})
function submenu() {
    var left = $(".avatarView").offset().left;
    $(".avatarView").css({'background-color':'#ffffff'})
    $(".avatarView").children('span').css('color','#498fca')
    $(".avatarView").children('div').attr('class','arrowimg-hover')
    $('.submenu').css({'left':left,'display':'block'});

    $('#naviframe', window.parent.document).css('height','220px')

//        $('.obj').css('z-index','20');
//        alert("submenu 出现 left ="+left);
//        alert($('.submenu').css('display'))
}
function submenuHover() {
    $(".avatarView").css({'background-color':'#fff'})
    $(".avatarView").children('span').css('color','#333')
    $(".avatarView").children('div').attr('class','arrowimg')
    $('.submenu').css('display','none');
    $('#naviframe', window.parent.document).css('height','60px')
//        $('.obj').css('z-index','-1');
}
/**
 * 判断鼠标从哪个方向进入和离开容器
 * @param {Object} tag JQuery对象，事件绑定的主体
 * @param {Object} e event对象
 * @return {Number} direction 值为“0,1,2,3”分别对应着“上，右，下，左”
 */
function moveDirection(tag,e){
    var w = $(tag).width();
    var h = $(tag).height();
    var x = (e.pageX - tag.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
    var y = (e.pageY - tag.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
    var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
    return direction;
}

function bindChange (paramenter) {
    $(paramenter).bind({
        mouseenter: function(e) {
            // Hover event handler
            var id = "#"+$(this).children("a").attr("id")
            $(id).css("color","#498fca");
            $(this).css("border-bottom","2px solid #498fca");
        },
        mouseleave: function(e) {
            // Hover event handler
            var id = "#"+$(this).children("a").attr("id")
            var pointer = $(this).css("pointer-events")
            if( pointer == "auto")
            {
                $(id).css("color","#333");
            }
            $(this).css("border-bottom","0px");
        }})
}
bindChange(".navButton")
function scrollTo(paramenter) {
    $('html, body').animate({
        scrollTop: $(paramenter).offset().top-$(".navgation").height() +20
    }, 500);

}


//    var selectedId = "#a1";

//    $(".navButton:first").css("background-color","#498fca")
//    $(".navButton:first").css("pointer-events","none")
//    $(selectedId).css("color","#fff")

//    navChange(selectedId)
function navChange(selectedId) {
    var parent = $(selectedId).parent()
    parent.css({"background-color":"#498fca","border-bottom":"0px","pointer-events":"none"})
    $(selectedId).css("color","#fff")

}


// footer ----js
$("#aboutus").on('click',function () {
//         alert('导航到关于我们')
    window.open('https:www.baidu.com');
})
$("#medium").on('click',function () {
//        alert('导航到媒体报道')
    window.open('../company/company.html');
})
$("#team").on('click',function () {
//        alert('导航到团队介绍')
    window.open('../company/company.html');
})
$("#contact").on('click',function () {
//        alert('导航到联系我们')
    window.open('../company/company.html');
})